/*************************************************************************************
*                                  SRL ENGINE                                        *
*                                                                                    *
*                                                                                    *
*  File : SRL_FrameBuffer.h                                                              *
*  Author: SRL Killing                                                               *
*  Date: 25/02/10 20:30                                                              *
*  Description:                                                                      *
*                                                                                    *  
*  Licence :  LGPL                                                                   *
*                                                                                    *
*    Copyright (C) 2010 Pecatte Baptiste                                             *
*                                                                                    *
*    This program is free software; you can redistribute it and/or                   *
*    modify it under the terms of the GNU Lesser General Public                      *
*    License as published by the Free Software Foundation; either                    *
*    version 2.1 of the License, or (at your option) any later version.              *
*                                                                                    *
*    This program is distributed in the hope that it will be useful,                 *
*    but WITHOUT ANY WARRANTY; without even the implied warranty of                  *
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU                *
*    Lesser General Public License for more details.                                 *
*                                                                                    *
*    You should have received a copy of the GNU Lesser General Public                *
*    License along with this program; if not, write to the Free Software             *
*    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    *
*                                                                                    *
**************************************************************************************/

#ifndef DefineHeaderFrameBuffer
#define DefineHeaderFrameBuffer

namespace srl {
    
    class FrameBuffer {
        public:
            FrameBuffer(int w, int h, int nbTex=1);
            ~FrameBuffer();
            void Init();
            void LinkTexture(srl::Texture* tex, int i);
    		void DeleteTexture(int i, bool replace);
    		
            void Use();
            void DUse();
            void Bind(int i=0);
            void DUseAndBind(int i=0);
            
           Texture *GetTex(int i=0);
            
            static GLenum CheckStatus();
        private:
            Texture** mTex;
            bool* mTexMadeIn;
            GLuint fbo;
            GLuint dbo;
    };
    
    	
	
	class FboConfig: public srl::Singleton<FboConfig> {
		public:
			bool Valid(int x);
			GLenum getFormat(int x);
			GLenum getIntFormat(int x);
			GLenum getDepth(int x);
			GLenum getStencil(int x);
			void __tryConfigs();
			bool __tryFormat(GLenum depthFormat, GLenum stencilFormat);
			bool __tryFormat(GLenum packedFormat); // For Packed Format (GL_DEPTH24_STENCIL8)
			
			FboConfig();
			~FboConfig();
			
			static const GLenum stencilFormats[];
			static const GLenum depthFormats[];
			
		private:
			struct DepthAndStencil { GLenum depth; GLenum stencil; };
			struct Config { bool valid; std::vector<DepthAndStencil> DAndS; };
			Config mConfs[51];
		
	};
	
    
};

#endif
